package com.sky.controller.user;


import com.atom.module.common.result.Result;
import com.sky.common.constant.StatusConstant;
import com.sky.pojo.entity.SetMeal;
import com.sky.pojo.vo.DishItemVO;
import com.sky.service.SetMealService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "套餐相关User接口")
@RequestMapping("/user/setmeal")
@RestController("userSetmealController")
@Slf4j
public class SetMealController {

    @Autowired
    private SetMealService setmealService;

    /**
     * 根据套餐id查询包含的菜品列表
     *
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @Operation(summary = "根据套餐id查询包含的菜品列表")
    public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
        List<DishItemVO> list = setmealService.getDishItemById(id);
        return Result.success(list);
    }


    /**
     * 条件查询
     *
     * @param categoryId
     * @return
     */
    // SpringCache使用，@Cacheable先查缓存，命中直接返回，否则调用方法，并将返回值存入缓存
    @Cacheable(cacheNames = "setmeal", key = "#categoryId")
    @GetMapping("/list")
    @Operation(summary = "根据分类id查询套餐")
    public Result<List<SetMeal>> list(Long categoryId) {
        SetMeal setmeal = new SetMeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);

        List<SetMeal> list = setmealService.list(setmeal);
        return Result.success(list);
    }

}
